// TODO: 这道是我什么时候做的什么题我怎么一点印象没有

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1010;
ll mat[N][N], n, m;
int a[N * N], b[N * N];
int lowbit(int x) { return x & -x; }
void add(int x, int y, int d) {
  for (int i = x; i <= n; i += lowbit(i))
    for (int j = y; j <= m; j += lowbit(j)) mat[i][j] += d;
}
ll sum(int x, int y) {
  if (x <= 0 || y <= 0) return 0;
  ll ret = 0;
  for (int i = x; i > 0; i -= lowbit(i))
    for (int j = y; j > 0; j -= lowbit(j)) ret += mat[i][j];
  return ret;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t, k, kase = 0;
  cin >> t;
  while (cin >> n >> m >> k) {
    memset(mat, 0, sizeof(mat));
    for (int i = 0; i < k; ++i) {
      cin >> a[i] >> b[i];
      add(a[i], b[i], 1);
    }
    ll ans = 0;
    for (int i = 0; i < k; ++i) {
      ans += sum(n, b[i] - 1) + sum(a[i] - 1, m) - sum(a[i], b[i] - 1) -
             sum(a[i] - 1, b[i]);
    }
    cout << "Test case " << ++kase << ": " << ans / 2 << endl;
  }
  return 0;
}
